package manage.commons.cookie;

import static manage.commons.cookie.UserStateConstants.TIMEOUT;

import java.io.Serializable;

public class UserState implements Serializable {
	private static final long serialVersionUID = 1L;

	private static final int SUPERMANGER = 1;
	private static final int REMEMBERME = 1;

	/** 用户id **/
	private Integer userId;
	/** 用户密码（加密后的） **/
	private String password;
	/** 登录时间戳 **/
	private long loginTime;
	/** 是否记住登录 (1:记住,0:一次性) **/
	private int remember;
	/** 是不是超级用户 (1:是,0:不是) **/
	private int superManager;

	public UserState() {

	}

	public UserState(Integer userId, String password, int remember,
			int superManager) {
		this.userId = userId;
		this.password = password;
		this.remember = remember;
		this.superManager = superManager;
	}

	public UserState(Integer userId, String password, long loginTime,
			int remember, int superManager) {
		this.userId = userId;
		this.password = password;
		this.loginTime = loginTime;
		this.remember = remember;
		this.superManager = superManager;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();

		return sb.toString();
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getRemember() {
		return remember;
	}

	public void setRemember(int remember) {
		this.remember = remember;
	}

	public long getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(long loginTime) {
		this.loginTime = loginTime;
	}

	public boolean isRememberMe() {
		return remember == REMEMBERME ? true : false;
	}

	public boolean isLoginTimeOut() {
		if (loginTime == 0 || loginTime + TIMEOUT > System.currentTimeMillis()) {
			return false;
		}
		return true;
	}

	public boolean isSuperManager() {
		return superManager == SUPERMANGER ? true : false;
	}

	public int getSuperManager() {
		return superManager;
	}

	public void setSuperManager(int superManager) {
		this.superManager = superManager;
	}

}
